﻿#include "mainwindow.h"

#include <QApplication>

#include "radiobutton.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

//#include <QApplication>
//#include "objparse.h" // 你的解析器头文件
//#include <Qt3DExtras/Qt3DWindow>
//#include <Qt3DExtras/QPhongMaterial>
//#include <Qt3DCore/QTransform>
//#include <Qt3DExtras/QOrbitCameraController>
//#include <Qt3DRender/QPointLight>
//#include <Qt3DRender/QCamera>
//#include <QGuiApplication>


//int main(int argc, char *argv[])
//{
//    qDebug() << "Qt Version:" << QT_VERSION_STR;

//    QApplication app(argc, argv);

//    // 1. 创建3D窗口和根实体
//    Qt3DExtras::Qt3DWindow view;
//    Qt3DCore::QEntity* rootEntity = new Qt3DCore::QEntity();

//    // 2. 设置相机
//    Qt3DRender::QCamera* camera = view.camera();
//    camera->setPosition(QVector3D(0, 0, 10.0f));
//    camera->setViewCenter(QVector3D(0, 0, 0));
//    camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);

//    // 3. 添加相机控制器
//    Qt3DExtras::QOrbitCameraController* camController = new Qt3DExtras::QOrbitCameraController(rootEntity);
//    camController->setCamera(camera);



//    // 4. 添加光源
//    Qt3DCore::QEntity* lightEntity = new Qt3DCore::QEntity(rootEntity);
//    Qt3DRender::QPointLight* light = new Qt3DRender::QPointLight(lightEntity);
//    light->setColor(Qt::white);
//    light->setIntensity(1.0f);
//    lightEntity->addComponent(light);
//    Qt3DCore::QTransform* lightTransform = new Qt3DCore::QTransform(lightEntity);
//    lightTransform->setTranslation(QVector3D(10.0f, 10.0f, 10.0f));
//    lightEntity->addComponent(lightTransform);

//    // 5. 解析OBJ文件并创建模型实体
//    ObjParse parser;
//    if (parser.parseObjFile("E:/data/Gen3D/Gen3D_Qt/data/data.obj","E:/data/Gen3D/data/material.mtl")) {
////    if (parser.parseObjFile("E:/data/Gen3D/data/car/car.obj", "")) {


//        // 获取模型中心
//        QVector3D modelCenter = parser.getModelCenter();
//        // 设置相机 view center 为模型中心
//        camera->setViewCenter(modelCenter);
//        // 调整相机位置，使其从“模型中心”后方 10 单位处观察
//        camera->setPosition(modelCenter + QVector3D(0, 0, 10));
//        // 鼠标滚轮缩放速度，与方向
//        camController->setLinearSpeed(10.0f); // 防止平移干扰
//        // 鼠标右键旋转速度，正值为相反方向，负值为与鼠标相同方向，大小为移动速度
//        camController->setLookSpeed(-180.0f);

//        // 替换原来的 modelEntity 创建逻辑
//        for (int i = 0; i < parser.m_meshParts.size(); ++i) {
//            Qt3DCore::QEntity* partEntity = new Qt3DCore::QEntity(rootEntity);

//            // 创建变换组件
//            Qt3DCore::QTransform* transform = new Qt3DCore::QTransform(partEntity);
//            transform->setScale(1.0f);
//            transform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));

//            partEntity->addComponent(parser.m_meshParts[i].renderer);
//            partEntity->addComponent(parser.m_meshParts[i].material);
//            partEntity->addComponent(transform); // 共享同一个 transform
//        }




////        Qt3DCore::QEntity* modelEntity = new Qt3DCore::QEntity(rootEntity);
////        // 创建几何体渲染器
////        Qt3DRender::QGeometryRenderer* meshRenderer = parser.createGeometryRenderer(modelEntity);

////        // 创建材质
////        Qt3DExtras::QPhongMaterial* material = new Qt3DExtras::QPhongMaterial(modelEntity);
////        material->setDiffuse(QColor(255, 0, 0)); // 红色材质
////        // 创建变换组件
////        Qt3DCore::QTransform* transform = new Qt3DCore::QTransform(modelEntity);
////        transform->setScale(1.0f);
////        transform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));
////        // 将组件添加到实体
////        modelEntity->addComponent(meshRenderer);
////        modelEntity->addComponent(material);
////        modelEntity->addComponent(transform);
//    } else {
//        qWarning() << "Failed to parse OBJ file";
//    }

//    // 6. 设置根实体并显示窗口
//    view.setRootEntity(rootEntity);
//    view.show();

//    qDebug() << "Current lookSpeed:" << camController->lookSpeed();

//    return app.exec();
//}

//#include <QApplication>
//#include <QMainWindow>
//#include <QWidget>
//#include <QVBoxLayout>

//#include "objparse.h"

//// Qt3D 头文件
//#include <Qt3DExtras/Qt3DWindow>
//#include <Qt3DCore/QEntity>
//#include <Qt3DRender/QCamera>
//#include <Qt3DExtras/QOrbitCameraController>
//#include <Qt3DRender/QPointLight>
//#include <Qt3DExtras/QPhongMaterial>
//#include <QTransform>

//int main(int argc, char *argv[])
//{
//    QApplication app(argc, argv);

//    // 创建主窗口
//    QMainWindow mainWindow;
//    mainWindow.resize(1200, 800);

//    // 创建 Qt3D 窗口（QWindow）
//    Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
////    view->defaultFrameGraph()->setClearColor(Qt::black);

//    // 使用 createWindowContainer 将 QWindow 嵌入 QWidget
//    QWidget *container = QWidget::createWindowContainer(view);
//    container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
//    // 可选：设置焦点策略，以便接收键盘事件
//    container->setFocusPolicy(Qt::StrongFocus);

//    // 将容器放入主窗口的中央区域
//    mainWindow.setCentralWidget(container);

//    // 创建场景根实体
//    Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
//    view->setRootEntity(rootEntity);

//    // 获取相机
//    Qt3DRender::QCamera *camera = view->camera();
//    camera->setPosition(QVector3D(0, 0, 10.0f));
//    camera->setViewCenter(QVector3D(0, 0, 0));
//    camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);

//    // 添加相机控制器
//    Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(rootEntity);
//    camController->setCamera(camera);

//    // 添加光源
//    Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
//    Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
//    light->setColor(Qt::white);
//    light->setIntensity(1.0f);
//    lightEntity->addComponent(light);

//    Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
//    lightTransform->setTranslation(QVector3D(10.0f, 10.0f, 10.0f));
//    lightEntity->addComponent(lightTransform);

//    // 解析 OBJ 文件并添加模型
//    ObjParse parser;
//    if (parser.parseObjFile("E:/data/Gen3D/Gen3D_Qt/data/data.obj",
//                            "E:/data/Gen3D/data/material.mtl")) {

//        QVector3D modelCenter = parser.getModelCenter();
//        camera->setViewCenter(modelCenter);
//        camera->setPosition(modelCenter + QVector3D(0, 0, 10));

//        camController->setLinearSpeed(10.0f);
//        camController->setLookSpeed(-180.0f);

//        // 添加每个部件
//        for (int i = 0; i < parser.m_meshParts.size(); ++i) {
//            Qt3DCore::QEntity *partEntity = new Qt3DCore::QEntity(rootEntity);

//            Qt3DCore::QTransform *transform = new Qt3DCore::QTransform(partEntity);
//            transform->setScale(1.0f);
//            transform->setTranslation(QVector3D(0, 0, 0));
//            partEntity->addComponent(transform);

//            partEntity->addComponent(parser.m_meshParts[i].renderer);
//            partEntity->addComponent(parser.m_meshParts[i].material);
//        }
//    } else {
//        qWarning() << "Failed to parse OBJ file.";
//    }

//    // 显示主窗口
//    mainWindow.show();

//    return app.exec();
//}

